package Zoo.Handler;


import Zoo.Entity.AnimalEntity;
import Zoo.Impl.ZoomenService1Impl;
import Zoo.Service.ZoomenService1;
import Zoo.View.ZoomanView.UpdateAnimalView;
import Zoo.View.ZoomanView.ZoomenView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UpdateAnimalViewHandler implements ActionListener {
    private UpdateAnimalView updateAnimalView;
    private ZoomenView1 zoomenView1;

//    public AddAnimalViewHandler(AddZoomenView addZoomenView, LeaderView1 leaderView1){
//        this.addZoomenView=addZoomenView;
//        this.leaderView1=leaderView1;
//    }

    public UpdateAnimalViewHandler(UpdateAnimalView updateAnimalView, ZoomenView1 zoomenView1) {
        this.updateAnimalView=updateAnimalView;
        this.zoomenView1=zoomenView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("修改".equals(text)){
            ZoomenService1 zoomenService1=new ZoomenService1Impl();
            AnimalEntity animalEntity =updateAnimalView.buildUpdatedZooparkEntity();
            boolean updateResult=zoomenService1.update(animalEntity);
            if(updateResult){
                //重新加载表格查到最新数据
                zoomenView1.reloadTable();
                updateAnimalView.dispose();
            }else{
                JOptionPane.showMessageDialog(updateAnimalView,"修改失败");

            }

        }
    }

}
